package com.project.service.imp;

import com.project.bean.RecordBean;
import com.project.mapper.IClassMapper;
import com.project.mapper.IRecordMapper;
import com.project.service.IRecordService;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;

public class RecordServiceImp extends BaseService implements IRecordService {

    @Override
    public ArrayList<RecordBean> showRecords(Integer roomId) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        ArrayList<RecordBean> rdList = mapper.showRecords(roomId);
        session.close();
        return rdList;
    }

    @Override
    public void addRecord(RecordBean recordBean) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        mapper.addRecord(recordBean);
        session.commit();
        session.close();
    }

    @Override
    public void processRecord(Integer recordId, Integer roomId) {
        SqlSession session = this.getSession();
        IRecordMapper mapper = session.getMapper(IRecordMapper.class);
        mapper.changeRecordState(recordId);
        Integer num =mapper.stateById(roomId);
        session.commit();
        if(num == 0){
            mapper.changeRoomState(roomId);
            session.commit();
            session.close();
        }
        session.close();
    }
}
